# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:scikit-learn1_0.py
@Time:2024/6/24 19:06

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
import streamlit as st

# 加载数据集
iris = load_iris()
# print(iris)
# print("*"*30)

X = iris.data
y = iris.target

# print(X)
# print("="*30)
# print(y)
# print("#"*30)

# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 创建决策树分类器实例
clf = DecisionTreeClassifier(random_state=42)

# 训练模型
clf.fit(X_train, y_train)

# 对测试集进行预测
y_pred = clf.predict(X_test)

# 计算预测准确率
accuracy = accuracy_score(y_test, y_pred)
st.write(f"Accuracy: {accuracy}")

# （可选）你可以将模型保存为文件，或者进行其他操作，如可视化等。